﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using TerrariaSvcCtrl;
using MySql.Data.MySqlClient;

namespace TerrariaSvcCtrl_Test {
    class Program {
        static void Main(string[] args) {

            string cs = @"server=vm-scilinux;userid=svenjd;password=Ph33l!72;database=terraria";
            MySqlConnection conn = null;

            //THIS WORKS
            //try {
            //    conn = new MySqlConnection(cs);
            //    conn.Open();
            //    Console.WriteLine("MySQL version : {0}", conn.ServerVersion);

            //} catch (MySqlException ex) {
            //    Console.WriteLine("Error: {0}", ex.ToString());

            //} finally {
            //    if (conn != null) {
            //        conn.Close();
            //    }
            //}


            //THIS WORKS
            //string output = "empty as my balls";
            //try {
            //    MySqlCommand cmd = new MySqlCommand("sp_GetOldestMOTD", new MySqlConnection(cs));
            //    cmd.CommandType = System.Data.CommandType.StoredProcedure;
            //    cmd.Connection.Open();
            //    output = (string)cmd.ExecuteScalar();
            //} catch (MySqlException ex) {
            //    Console.WriteLine("Error: {0}", ex.ToString());
            //} finally {
            //    if (conn != null) {
            //        conn.Close();
            //    }
            //}

            string output = "empty as my balls";
            //using (MySqlConnection con = new MySqlConnection(cs)) {
            //    try {
            //        con.Open();
            //        MySqlCommand cmd = new MySqlCommand("sp_GetOldestMOTD", con);
            //        cmd.CommandType = System.Data.CommandType.StoredProcedure;                    
            //        output = (string)cmd.ExecuteScalar();
            //    } catch (MySqlException ex) {
            //        Console.WriteLine("Error: {0}", ex.ToString());
            //    } finally {
            //        if (conn != null) {
            //            conn.Close();
            //        }
            //    }
            //}

            int motdSleepTimer = 1;

            using (MySqlConnection con = new MySqlConnection(cs)) {
                try {
                    con.Open();
                    MySqlCommand cmd = new MySqlCommand("sp_GetMOTDTimer", con);
                    cmd.CommandType = System.Data.CommandType.StoredProcedure;                    
                    motdSleepTimer = Int32.Parse((string)cmd.ExecuteScalar());
                    

                } catch (MySqlException ex) {
                    Console.WriteLine("Error: {0}", ex.ToString());
                } catch (Exception er) {
                    Console.WriteLine("Error: {0}", er.ToString());
                }                
            }



            Console.WriteLine(output);


            Console.WriteLine();
        }


    }

}